package com.cuit.dao.impl;

import com.cuit.dao.OrderDao;
import com.cuit.pojo.DoctorOrder;
import com.cuit.pojo.DoctorOrdered;
import com.cuit.pojo.Order;

import java.util.List;

public class OrderDaoImpl extends BaseDao implements OrderDao{


    @Override
    public int queryByIDFromDOrder(String d_id,int day) {
        String sql="select max_order from d_order where d_id=? and d_week=?";
        return (int)queryForSingleValue(sql,d_id,day);

    }

    @Override
    public int queryByIDFromOrder2(String d_id,int day) {
        String sql="select order_num from order2 where d_id=? and day=?";
        if( queryForSingleValue(sql,d_id,day)==null){
            System.out.println("没有人");
            return -1;
        }
        return (int)queryForSingleValue(sql,d_id,day);
    }

    @Override
    public List<Order> queryByID(String id) {
        String sql="select * from order1 where p_id=?";
        return queryForList(Order.class,sql,id);
    }

    @Override
    public Order queryOneOrder(String p_id, String d_id, int day, String time) {
        String sql="select * from order1 where p_id=? and d_id=? and day=? and time=?";
        return queryForOne(Order.class,sql,p_id,d_id,day,time);
    }

    @Override
    public int addInfoToOrder(Order order) {
        String sql="insert into order1(`p_id`,`patient`,`d_id`,`doctor`,`time`,`day`) values(?,?,?,?,?,?)";
        return update(sql,order.getP_id(),order.getPatient(),order.getD_id(),order.getDoctor(),order.getTime(),order.getDay());
    }

    @Override
    public int saveInfoToOrder2(String doctor_id, int day) {
        String sql="update order2 set `order_num`=`order_num`+1 where d_id=? and day=?";
        return update(sql,doctor_id,day);
    }

    @Override
    public int deleteFromOrder1(String p_id, String d_id, String time, int day) {
        String sql="delete from order1 where p_id=? and d_id=? and time=? and day=?";
        return update(sql,p_id,d_id,time,day);
    }

    @Override
    public int updateFromOrder2(String id, int day) {
        String sql="update order2 set `order_num`=`order_num`-1 where d_id=? and day=?";
        return update(sql,id,day);
    }


    @Override
    public int saveNewInfoToOrder2(String doctor_id, int day) {
        String sql="insert into order2 values(?,?,?)";
        return update(sql,doctor_id,day,1);
    }
}
